umei.asideWidth = 230;
$(function() {
    umei.windowViewHeight = $(window).height();
    umei.documentHeight = $(document).height();
    umei.windowHeight = $(window).height();
    umei.scrollTop = $(document).scrollTop();
    $("ul.ul-menu li a.have-sub").click(function() {
	var is = $(this).find("i");
	var index = 0;
	if (is.length > 1) {
	    index = 1;
	}
	var i = $(this).find("i").eq(index);
	if (i.prop("class") == "open") {
	    i.prop("class", "close");
	} else {
	    i.prop("class", "open");
	}
	var curUl = $(this).parent().find(">ul");
	curUl.slideToggle();
    });

    initCircle();
    initAside();
    initToggleMenuBtn();
    // 初始化列表
    initDataList();
})
/**
 * 初始化菜单图标
 */

function initCircle() {
    var fa_circle_colors = [ "fa-circle-red", "fa-circle-yellow", "fa-circle-aqua", "fa-circle-blue", "fa-circle-light-blue", "fa-circle-green", "fa-circle-gray", "fa-circle-teal", "fa-circle-lime",
	    "fa-circle-orange", "fa-circle-fuchsia", "fa-circle-purple", "fa-circle-maroon" ];
    var _fa_circle_lenth = fa_circle_colors.length;
    var i_s = $("i.fa-circle");
    for (var i = 0, _len = i_s.length; i < _len; i++) {
	var c_index = i < _fa_circle_lenth ? i : i % _fa_circle_lenth;
	i_s.eq(i).addClass(fa_circle_colors[c_index]);
    }
}
/**
 * 初始化左侧高度
 */
function initAside() {

    var height = umei.windowViewHeight - $("#header").height();
    $("#aside").css({
	"height" : height + "px"
    })
}

/**
 * 初始化收起菜单按钮
 */
function initToggleMenuBtn() {
    // 网页可视化高度
    var viewHeight = umei.windowHeight;
    $(".toggle-menu-btn").css({
	"top" : (viewHeight / 2) + "px"
    });
    $(".toggle-menu-btn a").click(function() {
	var type = $(this).attr("type");
	var i = $(this).find("i");
	if (type == "open") {
	    i.removeClass("close");
	    i.addClass("open");
	    $(this).attr("type", "close");
	    $(".toggle-menu-btn").css({
		"left" : "0px"
	    });
	    $("#aside").hide();
	    $(".content").eq(0).css({
		"marginLeft" : "0px"
	    });
	} else {
	    i.removeClass("open");
	    i.addClass("close");
	    $(this).attr("type", "open");
	    $(".toggle-menu-btn").css({
		"left" : umei.asideWidth + "px"
	    });
	    $("#aside").show();
	    $(".content").eq(0).css({
		"marginLeft" : umei.asideWidth + "px"
	    });
	}
    });
}

function initDataList() {
    var content_header_paddingtop = 25;
    var pagination_padding = 20;
    // 顶部 头信息的高度
    var top_height = $("#header").height();
    // 模块title,搜索区域的高度
    var content_head_height = $("#content-head").height();
    content_head_height = content_head_height == null ? 0 : content_head_height;
    // grid标题的高度
    var grid_header_height = $(".grid-list-title").height();
    grid_header_height = grid_header_height == null ? 0 : grid_header_height;
    // 分页栏的高度
    var pagination_height = $("#pager").height();
    pagination_height = pagination_height == null ? 0 : pagination_height;
    // 其他信息
    var footer_info_height = $(".footer-info").height();
    footer_info_height = footer_info_height == null ? 0 : footer_info_height;
    var content_padding = 20;
    var content_head_padding = 10;
    var pagination_padding = 10;
    var other_height = content_padding + content_head_padding + pagination_padding + footer_info_height;
    var data_list_height = umei.documentHeight - umei.scrollTop - top_height - content_head_height - grid_header_height - pagination_height - other_height;
    $(".grid-list").css({
	"maxHeight" : data_list_height + "px"
    });

    var tabletitle = $(".grid-list-title table");
    var trtitle = tabletitle.find("tr");
    var ths = trtitle.find("th");
    var _blankTr = $("<tr class='blank_tr'></tr>").appendTo($("#pager_content"));
    for (var i = 0, _len = ths.length; i < _len; i++) {
	$("<td></td>").appendTo(_blankTr);
    }
    var firstTr = $(".grid-list table tr").eq(0);
    var data_tds = firstTr.find("td");
    var haveNoWidth = false;
    for (var i = 0, _len = data_tds.length; i < _len; i++) {
	var tdWidth = ths.eq(i).attr("width");
	if (typeof (tdWidth) != "undefined") {
	    data_tds.eq(i).attr("width", ths.eq(i).attr("width"));
	} else {
	    haveNoWidth = true;
	}
    }
    if (!haveNoWidth) {
	data_tds.eq(data_tds.length - 1).removeAttr("width");
	ths.eq(data_tds.length - 1).removeAttr("width");
    }
}